import {getData,addquset,xgData,delData} from "../../api/exam"

export default {
    namespaced: true,
    state: {
        questArr:[],
        currentPage: 0,
        pageSize: 10,
        total: 0,
        classify:[],
        sort: 'desc',
        order: 'id',
    },
    mutations: {
        getDataMut(state,val){
            state.questArr=val
        },
        settotal(state, total) {
            state.total = total
        },
        getcurrentSize(state, page) {
            state.currentPage = page-1
        },
        getpageSize(state, size) {
            state.pageSize = size
        },
        sortChange(state, data) {
            if (data.order == 'descending') { // 降序
                state.sort = "desc"
                state.order = data.prop
            } else if (data.order == "ascending") { //升序
                state.sort = 'asc'
                state.order = data.prop
            } else {
                state.sort = 'desc'
                state.order = 'id'
            }
        }
    },
    actions: {
        async getData({commit,state}) {
            let r = await getData({ currentPage: state.currentPage, pageSize: state.pageSize, keyword: state.search, sort: state.sort,orderby: state.order, })
            commit('getDataMut',r.data)
            console.log(r)
            commit("settotal",r.total[0].total)
            console.log(r.total[0].total)
        },
    },
    getters: {

    }
}